package com.dces.demo.executor;


import com.dces.jx.billtest.config.MyBatisMapperScannerConfig;
import com.xdo.common.support.TokenUserHandlerMethodArgumentResolver;
import com.xdo.pcode.service.PCodeHolder;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Import;
import org.springframework.web.method.support.HandlerMethodArgumentResolver;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.util.List;

/**
 * @author xuxueli 2018-10-28 00:38:13
 */
@SpringBootApplication
@Import({   MyBatisMapperScannerConfig.class})
@ComponentScan({"com.dces.demo", "com.xdo.dataimport.**", "com.xdo.springboot.**", "com.xdo.findsword", "com.xdo.mybatis","com.xdo.multidb"})
public class XxlJobExecutorApplication extends SpringBootServletInitializer implements WebMvcConfigurer {

	@Value("${dc.pcode.url}")
	private String pcodeUrl;

	@Bean
	public PCodeHolder getPCodeHolder() {
		String[] initialPCodes = new String[]{"CIQ_ENTY_PORT", "CURR_OUTDATED", "COUNTRY_OUTDATED", "EXCHANGE_CUSTOMS_CURRENT",
				"AREA", "TRADE", "UNIT", "COUNTRY", "PORT_LIN", "LEVYMODE", "LC_TYPE", "TRANSF", "USE_TO", "CURR", "CUSTOMS_REL",
				"TRANSAC", "WRAP", "LICENSEDOCU", "CO_TYPE", "DIST_TYPE", "COMPLEX", "LEVYTYPE", "PRODUCT_TYPE_MNL", "PORT_LIN_OUTDATED",
				"TRADE_OUTDATED", "TRANSF_OUTDATED", "WRAP_OUTDATED", "GOODS_ATTR", "WRAP_OUTDATED", "AGREEMENT_TYPE", "POST_AREA"};
		PCodeHolder pCodeHolder = new PCodeHolder(pcodeUrl, initialPCodes);
		return pCodeHolder;
	}

	@Override
	public void addArgumentResolvers(List<HandlerMethodArgumentResolver> resolvers) {
		resolvers.add(new TokenUserHandlerMethodArgumentResolver());
	}

	public static void main(String[] args) {
		SpringApplication.run(XxlJobExecutorApplication.class, args);
	}

	@Override
	protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
		return builder.sources(XxlJobExecutorApplication.class);
	}

}